package cn.wildfirechat.app.jpa;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.time.LocalDateTime;

@RepositoryRestResource()
public interface TeenStatusRepository extends JpaRepository<TeenStatus, Long> {
    @Modifying
    @Query(value = "UPDATE teen_status ts SET ts.status = ?1 WHERE ts.uid = ?2", nativeQuery = true)
    void updateTeenagerStatusByUid(Integer status,String uid);

    @Query(value = "select count(*) from teen_status ts WHERE ts.uid = ?1", nativeQuery = true)
    int countByUid(String userId);

    @Modifying
    @Query(value = "INSERT INTO teen_status (uid, status, created_at, updated_at) VALUES (?1, ?2, ?3, ?4)", nativeQuery = true)
    int insertTeenStatus(String uid, Integer status, LocalDateTime createdAt, LocalDateTime updatedAt);

    @Query(value = "select * from teen_status ts WHERE ts.uid = ?1", nativeQuery = true)
    TeenStatus findByUid(String userId);
}
